Sending Files to and from Your Server via SSH
Prerequisites
- SSH access to your server.
scpinstalled on your local machine (it comes pre-installed on most Unix-based systems).
Sending a File to Your Server
-
Ensure you have SSH access to your server:
ssh your_username@your_server_ip -
Use
scpto send a file from your local machine to your server:scp /path/to/local/file your_username@your_server_ip:/path/to/remote/destinationExample
To send
example.txtfrom your local~/Documentsdirectory to the/home/your_usernamedirectory on your server:scp ~/Documents/example.txt your_username@your_server_ip:/home/your_username/ -
Enter your SSH password when prompted.
-
Verify the file transfer by logging into your server and checking the destination directory:
ssh your_username@your_server_ip
ls /home/your_username/
Downloading a File from Your Server
-
Ensure you have SSH access to your server:
ssh your_username@your_server_ip -
Use
scpto download a file from your server to your local machine:scp your_username@your_server_ip:/path/to/remote/file /path/to/local/destinationExample
To download
example.txtfrom the/home/your_usernamedirectory on your server to your local~/Downloadsdirectory:scp your_username@your_server_ip:/home/your_username/example.txt ~/Downloads/ -
Enter your SSH password when prompted.
-
Verify the file transfer by checking the destination directory on your local machine:
ls ~/Downloads/
Additional Tips
-
Uploading/Downloading a Directory:
- Use the
-r(recursive) option to upload/download entire directories.# Upload a directory
scp -r /path/to/local/directory your_username@your_server_ip:/path/to/remote/destination
# Download a directory
scp -r your_username@your_server_ip:/path/to/remote/directory /path/to/local/destination
- Use the
-
Specifying a Different SSH Port:
- If your SSH server uses a different port, use the
-Poption.# Uploading with a specific port
scp -P 2222 /path/to/local/file your_username@your_server_ip:/path/to/remote/destination
# Downloading with a specific port
scp -P 2222 your_username@your_server_ip:/path/to/remote/file /path/to/local/destination
- If your SSH server uses a different port, use the
-
Get your actual system location:
-
Run the pwd Command
Simply type pwd and press Enter.
pwdExample Output
If you are in your home directory, the output might look something like this:
/home/your_username
-
By following this tutorial, you can easily send files to and from your server via SSH using scp.